package com.wz.jiangsu.controller.es;

import com.wz.jiangsu.bean.entity.wazuh.WazuhSecurityEventDataCommonDtoToES;
import com.wz.jiangsu.bean.vo.es.QueryESCondition;
import com.wz.jiangsu.bean.vo.es.WazuhSecurityEventDataCommonVo;
import com.wz.jiangsu.bean.vo.resp.PageResult;
import com.wz.jiangsu.bean.vo.resp.R;
import com.wz.jiangsu.service.es.ESWazuhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: wz
 * @author: wangzhou
 * @create: 2023-12-31 21:41
 * @description:
 **/

@RestController
@RequestMapping("/wauzh")
public class ESWazuhController {

    @Autowired
    private ESWazuhService esWazuhService;


    /**
     * 通过主键 id 进行寻找
     *
     * @param id
     * @return
     */
    @GetMapping("/get/findById")
    public R<WazuhSecurityEventDataCommonDtoToES> findById(@RequestParam("id") String id) {
        return esWazuhService.findById(id);
    }

    /**
     * 进行新增或者是更新,判读是否更新根据主键进行判断
     *
     * @param vo
     * @return
     */
    @PostMapping("/post/saveOrUpdateById")
    public R<WazuhSecurityEventDataCommonDtoToES> saveOrUpdateById(@RequestBody WazuhSecurityEventDataCommonVo vo) {
        return esWazuhService.saveOrUpdateById(vo);
    }

    /**
     * 查询 wauzh 数据库的数量
     *
     * @return
     */
    @GetMapping("/get/count")
    public R<Long> count() {
        return esWazuhService.count();
    }

    /**
     * 清空所有的数据
     */
    @DeleteMapping("/delete/deleteAll")
    public R<Boolean> deleteAll() {
        return esWazuhService.deleteAll();
    }

    /**
     * 通过 ts 进行查询数据
     * @param ts
     * @return
     */
    @GetMapping("/get/findByTs")
    public R<PageResult<List<WazuhSecurityEventDataCommonDtoToES>>> getListByTs(@RequestParam("ts") Long ts) {
        return esWazuhService.findByTs(ts);
    }

    /**
     * 条件查询  es 数据库
     * @param vo
     * @return
     */
    @PostMapping("/post/findByQueryESConditon")
    public R<PageResult<List<WazuhSecurityEventDataCommonDtoToES>>> getResultByQueryESCondition(@RequestBody QueryESCondition vo){
        return esWazuhService.getResultByQueryESCondition(vo);
    }


}
